<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>、
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>修改登录信息</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/bootstrap/css/bootstrap.css" media="all">
    <script type="text/javascript" src="${pageContext.request.contextPath}/common/bootstrap/js/jquery-1.12.4.js"></script>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/bootstrap/css/bootstrap-select.css">
</head>
<body>
<div class="container">
    <c:set value="${meaningUser}" var="meaninguser" />
    <form role="form" id="find_btn" class="form-horizontal" action="../../loginRegistered/updateMeaningUser" method="post">
        <div class="form-group col-sm-12" style="height: 50px;">
            <h2><small style="color: red;"><b>个人信息：</b></small></h2>
        </div>
        <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-3">
                <input class="form-control" id="username" name="username" value="${meaninguser.username}" readonly>
            </div>
            <label class="col-sm-2 control-label">用户别名</label>
            <div class="col-sm-3">
                <input name="userAlias" id="userAlias" class="form-control" value="${meaninguser.userAlias}" />
            </div>
        </div>
        <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-3">
                <span id="usernameSpan" ></span>
            </div>
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-3">
                <input value="${meaninguser.userId}" name="userId" class="form-control" type="hidden" />
            </div>
        </div>
        <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label">工号</label>
            <div class="col-sm-3">
                <input class="form-control" id="jobNumber" name="jobNumber" value="${meaninguser.jobNumber}" >
            </div>
            <label class="col-sm-2 control-label">所属科室</label>
            <div class="col-sm-3">
                <select name="departmentId" class="form-control"  readonly>
                    <option value="${meaninguser.departmentId}">${meaninguser.departmentName}</option>
                </select>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label">性别</label>
            <div class="col-sm-3">
                <select class="form-control" name="userSex">
                    <option value="">请选择</option>
                    <option value="1" ${meaninguser.userSex==1?'selected':'' } >男</option>
                    <option value="2" ${meaninguser.userSex==2?'selected':'' } >女</option>
                </select>
            </div>
            <label class="col-sm-2 control-label">年龄</label>
            <div class="col-sm-3">
                <input class="form-control" id="userAge" name="userAge" value="${meaninguser.userAge}" >
            </div>
        </div>
        <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label">邮箱</label>
            <div class="col-sm-3">
                <input class="form-control" id="userEmail" name="userEmail" value="${meaninguser.userEmail}" >
            </div>
            <label class="col-sm-2 control-label">电话</label>
            <div class="col-sm-3">
                <input class="form-control" id="userPhone" name="userPhone" value="${meaninguser.userPhone}" >
            </div>
        </div>
        <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-3">
                <span id="userEmailSpan" ></span>
            </div>
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-3">
                <span id="userPhoneSpan" ></span>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label">入职时间</label>
            <div class="col-sm-3">
                <fmt:formatDate value="${meaninguser.userDatetime}" var="time" pattern="yyyy-MM-dd"></fmt:formatDate>
                <input class="form-control" name="userDatetimeStr" value="${time}" type="date" >
            </div>
            <label class="col-sm-2 control-label">职位</label>
            <div class="col-sm-3">
                <select class="form-control" name="roleId" readonly>
                    <option value="${meaninguser.roleId}">${meaninguser.roleName}</option>
                </select>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-8">
                <span id="btn_personal_span"></span>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-8">
                <button type="button" id="btn_personal" class="btn btn-primary btn-block">（保存）</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function(){
        var index1 = true;
        var index2 = true;
        var index3 = true;
        /**
         * 验证用户名不能为admin
         */
        $("#username").blur(function () {
            var name = $("#username").val()
            if (name.trim() == null && name.trim() == "" ) {
                $("#usernameSpan").text("账号不能为空").css("color", "red");
                index1 = false;
            } else if( name == "admin" ){
                $("#usernameSpan").text("用户名不能为（admin）").css("color", "red");
                index1 = false;
            }else{
                $("#usernameSpan").text("").css("color", "green");
                index1 = true;
            }
        })

        /**
         * 验证邮箱不能重复
         */
        $("#userEmail").blur(function () {
            var str = $("#userEmail").val();
            var patrn = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            if (patrn.test(str) == false) {
                $("#userEmailSpan").text("邮箱输入格式有误").css("color", "red");
                index2 = false;
            } else {
                $.ajax({
                    url: "../../loginRegistered/findByUserEmail",
                    type: "post",
                    dataType: "json",
                    data: {
                        email: str
                    },
                    success: function (map) {
                        var count = map.count;
                        if (count != 0) {
                            $("#userEmailSpan").text("邮箱重复").css("color", "red");
                            index2 = false;
                        } else {
                            $("#userEmailSpan").text("").css("color", "green");
                            index2 = true;
                        }
                    },
                    error: function () {
                        window.location.href = "../../404.jsp";
                    }
                });
            }
        });

        /**
         * 验证电话不能重复
         */
        $("#userPhone").blur(function () {
            var str = $("#userPhone").val();
            var patrn = /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/;
            if (patrn.test(str) == false) {
                $("#userPhoneSpan").text("手机号输入有误").css("color", "red");
                index3 = false;
            } else {
                $.ajax({
                    url: "../../loginRegistered/findByUserPhone",
                    type: "post",
                    dataType: "json",
                    data: {
                        phone: str
                    },
                    success: function (map) {
                        var count = map.count;
                        if (count != 0) {
                            $("#userPhoneSpan").text("手机号重复").css("color", "red");
                            index3 = false;
                        } else {
                            $("#userPhoneSpan").text("").css("color", "green");
                            index3 = true;
                        }
                    },
                    error: function () {
                        window.location.href = "../../404.jsp";
                    }
                });
            }
        });

        /**
         * 保存按钮，执行修改登录人信息操作
         */
        $("#btn_personal").click(function(){
            if( index1 == true && index2 == true && index3 == true ){
                $("#find_btn").submit();
            }else{
                $("#btn_personal_span").text("请填写正确的个人信息").css("color", "red");
            }
        })

    })
</script>
</body>
</html>